home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / dcon.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  212 lines

  1. /***************************************************************************
  2.  
  3.     D-Con video hardware.
  4.  
  5. ***************************************************************************/
  6.  
  7. #include "driver.h"
  8. #include "vidhrdw/generic.h"
  9.  
  10. static struct tilemap *background_layer,*foreground_layer,*midground_layer,*text_layer;
  11. unsigned char *dcon_back_data,*dcon_fore_data,*dcon_mid_data,*dcon_scroll_ram;
  12. static int dcon_enable;
  13.  
  14. /******************************************************************************/
  15.  
  16. WRITE_HANDLER( dcon_control_w )
  17. {
  18.     dcon_enable=data;
  19.     if ((dcon_enable&4)==4)
  20.         tilemap_set_enable(foreground_layer,0);
  21.     else
  22.         tilemap_set_enable(foreground_layer,1);
  23.  
  24.     if ((dcon_enable&2)==2)
  25.         tilemap_set_enable(midground_layer,0);
  26.     else
  27.         tilemap_set_enable(midground_layer,1);
  28.  
  29.     if ((dcon_enable&1)==1)
  30.         tilemap_set_enable(background_layer,0);
  31.     else
  32.         tilemap_set_enable(background_layer,1);
  33. }
  34.  
  35. WRITE_HANDLER( dcon_background_w )
  36. {
  37.     COMBINE_WORD_MEM(&dcon_back_data[offset],data);
  38.     tilemap_mark_tile_dirty( background_layer,offset/2);
  39. }
  40.  
  41. WRITE_HANDLER( dcon_foreground_w )
  42. {
  43.     COMBINE_WORD_MEM(&dcon_fore_data[offset],data);
  44.     tilemap_mark_tile_dirty( foreground_layer,offset/2);
  45. }
  46.  
  47. WRITE_HANDLER( dcon_midground_w )
  48. {
  49.     COMBINE_WORD_MEM(&dcon_mid_data[offset],data);
  50.     tilemap_mark_tile_dirty( midground_layer,offset/2);
  51. }
  52.  
  53. WRITE_HANDLER( dcon_text_w )
  54. {
  55.     COMBINE_WORD_MEM(&videoram[offset],data);
  56.     tilemap_mark_tile_dirty( text_layer,offset/2);
  57. }
  58.  
  59. static void get_back_tile_info(int tile_index)
  60. {
  61.     int tile=READ_WORD(&dcon_back_data[2*tile_index]);
  62.     int color=(tile>>12)&0xf;
  63.  
  64.     tile&=0xfff;
  65.  
  66.     SET_TILE_INFO(1,tile,color)
  67. }
  68.  
  69. static void get_fore_tile_info(int tile_index)
  70. {
  71.     int tile=READ_WORD(&dcon_fore_data[2*tile_index]);
  72.     int color=(tile>>12)&0xf;
  73.  
  74.     tile&=0xfff;
  75.  
  76.     SET_TILE_INFO(2,tile,color)
  77. }
  78.  
  79. static void get_mid_tile_info(int tile_index)
  80. {
  81.     int tile=READ_WORD(&dcon_mid_data[2*tile_index]);
  82.     int color=(tile>>12)&0xf;
  83.  
  84.     tile&=0xfff;
  85.  
  86.     SET_TILE_INFO(3,tile,color)
  87. }
  88.  
  89. static void get_text_tile_info(int tile_index)
  90. {
  91.     int tile=READ_WORD(&videoram[2*tile_index]);
  92.     int color=(tile>>12)&0xf;
  93.  
  94.     tile&=0xfff;
  95.  
  96.     SET_TILE_INFO(0,tile,color)
  97. }
  98.  
  99. int dcon_vh_start(void)
  100. {
  101.     background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,     16,16,32,32);
  102.     foreground_layer = tilemap_create(get_fore_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
  103.     midground_layer =  tilemap_create(get_mid_tile_info, tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
  104.     text_layer =       tilemap_create(get_text_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,  8,8,64,32);
  105.  
  106.     if (!background_layer || !foreground_layer || !midground_layer || !text_layer)
  107.         return 1;
  108.  
  109.     midground_layer->transparent_pen = 15;
  110.     foreground_layer->transparent_pen = 15;
  111.     text_layer->transparent_pen = 15;
  112.  
  113.     return 0;
  114. }
  115.  
  116. static void draw_sprites(struct osd_bitmap *bitmap,int pri)
  117. {
  118.     int offs,fx,fy,x,y,color,sprite;
  119.     int dx,dy,ax,ay;
  120.  
  121.     for (offs = 0x800-8;offs >= 0;offs -= 8)
  122.     {
  123.         if ((READ_WORD(&spriteram[offs+0])&0x8000)!=0x8000) continue;
  124.         sprite = READ_WORD(&spriteram[offs+2]);
  125.         if ((sprite>>14)!=pri) continue;
  126.         sprite &= 0x3fff;
  127.  
  128.         y = READ_WORD(&spriteram[offs+6]);
  129.         x = READ_WORD(&spriteram[offs+4]);
  130.  
  131.         if (x&0x8000) x=0-(0x200-(x&0x1ff));
  132.         else x&=0x1ff;
  133.         if (y&0x8000) y=0-(0x200-(y&0x1ff));
  134.         else y&=0x1ff;
  135.  
  136.         color = READ_WORD(&spriteram[offs+0])&0x3f;
  137.         fx = 0; /* To do */
  138.         fy = 0; /* To do */
  139.         dy=((READ_WORD(&spriteram[offs+0])&0x0380)>>7)+1;
  140.         dx=((READ_WORD(&spriteram[offs+0])&0x1c00)>>10)+1;
  141.  
  142.         for (ax=0; ax<dx; ax++)
  143.             for (ay=0; ay<dy; ay++) {
  144.                 drawgfx(bitmap,Machine->gfx[4],
  145.                 sprite++,
  146.                 color,fx,fy,x+ax*16,y+ay*16,
  147.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  148.             }
  149.     }
  150. }
  151.  
  152. static void mark_sprite_colours(void)
  153. {
  154.     int colmask[64],i,pal_base,color,offs,sprite,multi;
  155.  
  156.     pal_base = Machine->drv->gfxdecodeinfo[4].color_codes_start;
  157.     for (color = 0;color < 64;color++) colmask[color] = 0;
  158.     for (offs = 8;offs <0x800;offs += 8)
  159.     {
  160.         color = READ_WORD(&spriteram[offs+0])&0x3f;
  161.         sprite = READ_WORD(&spriteram[offs+2]);
  162.         sprite &= 0x3fff;
  163.         multi=(((READ_WORD(&spriteram[offs+0])&0x0380)>>7)+1)*(((READ_WORD(&spriteram[offs+0])&0x1c00)>>10)+1);
  164.  
  165.         for (i=0; i<multi; i++)
  166.             colmask[color] |= Machine->gfx[4]->pen_usage[(sprite+i)&0x3fff];
  167.     }
  168.     for (color = 0;color < 64;color++)
  169.     {
  170.         for (i = 0;i < 15;i++)
  171.         {
  172.             if (colmask[color] & (1 << i))
  173.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  174.         }
  175.     }
  176. }
  177.  
  178. void dcon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  179. {
  180.     /* Setup the tilemaps */
  181.     tilemap_set_scrollx( background_layer,0, READ_WORD(&dcon_scroll_ram[0]) );
  182.     tilemap_set_scrolly( background_layer,0, READ_WORD(&dcon_scroll_ram[2]) );
  183.     tilemap_set_scrollx( midground_layer, 0, READ_WORD(&dcon_scroll_ram[4]) );
  184.     tilemap_set_scrolly( midground_layer, 0, READ_WORD(&dcon_scroll_ram[6]) );
  185.     tilemap_set_scrollx( foreground_layer,0, READ_WORD(&dcon_scroll_ram[8]) );
  186.     tilemap_set_scrolly( foreground_layer,0, READ_WORD(&dcon_scroll_ram[0xa]) );
  187.  
  188.     tilemap_update(ALL_TILEMAPS);
  189.  
  190.     /* Build the dynamic palette */
  191.     palette_init_used_colors();
  192.     mark_sprite_colours();
  193.  
  194.     if (palette_recalc())
  195.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  196.  
  197.     tilemap_render(ALL_TILEMAPS);
  198.  
  199.     if ((dcon_enable&1)!=1)
  200.         tilemap_draw(bitmap,background_layer,0);
  201.     else
  202.         fillbitmap(bitmap,palette_transparent_pen,&Machine->drv->visible_area);
  203.  
  204.     draw_sprites(bitmap,2);
  205.     tilemap_draw(bitmap,midground_layer,0);
  206.     draw_sprites(bitmap,1);
  207.     tilemap_draw(bitmap,foreground_layer,0);
  208.     draw_sprites(bitmap,0);
  209.     draw_sprites(bitmap,3);
  210.     tilemap_draw(bitmap,text_layer,0);
  211. }
  212.